package cn.ym.ymcc.service.impl;

import cn.ym.ymcc.domain.CourseChapter;
import cn.ym.ymcc.domain.CourseChapter;
import cn.ym.ymcc.mapper.CourseChapterMapper;
import cn.ym.ymcc.query.CourseChapterQuery;
import cn.ym.ymcc.result.PageList;
import cn.ym.ymcc.service.ICourseChapterService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 课程章节 ， 一个课程，多个章节，一个章节，多个视频 服务实现类
 * </p>
 *
 * @author 210513347@qq.com
 * @since 2023-05-08
 */
@Service
public class CourseChapterServiceImpl extends ServiceImpl<CourseChapterMapper, CourseChapter> implements ICourseChapterService {

    
    @Autowired
    private CourseChapterMapper courseChapterMapper;
    @Override
    public PageList<CourseChapter> queryPage(CourseChapterQuery query) {
        Wrapper<CourseChapter> wrapper = new EntityWrapper<>();
        wrapper.like("name", query.getKeyword());
        Long count = Long.valueOf(courseChapterMapper.selectCount(wrapper));
        if(count==0){
            return new PageList<>();
        }
        List<CourseChapter> courseChapters = courseChapterMapper.queryData(query);
        return new PageList<>(count, courseChapters);
    }

    @Override
    public List<CourseChapter> listByCourseId(Long courseId) {
        Wrapper<CourseChapter> wrapper =new EntityWrapper<>();
        wrapper.eq("course_id",courseId);
        return courseChapterMapper.selectList(wrapper);
    }
}
